home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / WMS.CAB / wmsFileIO.inc < prev    next >
Encoding:
Text File  |  2003-02-21  |  20.3 KB  |  679 lines

  1. <%
  2. '+-------------------------------------------------------------------------
  3. '
  4. '  Microsoft Windows Media
  5. '  Copyright (C) Microsoft Corporation. All rights reserved.
  6. '
  7. '  File:       WMSFileIO.asp
  8. '
  9. '  Contents:   Code for performing XML file I/O (server list file)
  10. '
  11. '  Dependencies:  LocStrings.asp, WMSConstants.asp
  12. '
  13. '--------------------------------------------------------------------------
  14.  
  15. Dim g_strErrorDescription
  16. Dim g_strLocalHostName
  17. Dim g_strLocalHostDNSName
  18. Dim g_strLocalHostIP
  19. Dim g_strDomainName
  20. Dim g_strXMLPath
  21. Dim g_bServerlistFileExists
  22. Dim g_bRequireSSL
  23. Dim g_bNeverShowSSLWarning
  24. Dim g_FileSysObj
  25. Dim g_bLocalHostRunningWMS
  26. Dim g_xmlDoc
  27. Dim g_xmlRootNode
  28. Dim g_dwNumAvailableServers
  29. Dim g_bWellFormedXML
  30. Dim g_bInitialized
  31.  
  32. g_bInitialized = FALSE
  33. on error resume next
  34.  
  35. '////////////////////////////////////////////////////////////////
  36. Sub InitializeFileIO()
  37.  
  38.     g_bWellFormedXML = FALSE
  39.     g_strErrorDescription = ""
  40.  
  41.     g_xmlRootNode = empty
  42.     g_xmlDoc = empty
  43.    
  44.     if( IsEmpty( g_FileSysObj ) ) then
  45.         Set g_FileSysObj = Server.CreateObject( "Scripting.FileSystemObject" )
  46.     end if
  47.     
  48.     g_strXMLPath = BuildPathToXMLServerList
  49.  
  50.     Application.Lock
  51.     g_bLocalHostRunningWMS = Application( "bLocalHostHasWMS" )
  52.     g_strLocalHostName = Application( "strLocalHostName" )
  53.     g_strDomainName = Application( "strDomainName" )
  54.     g_strLocalHostDNSName = Application( "strLocalHostDNSName" )
  55.     g_strLocalHostIP = Application( "strHostIPAddress" )
  56.     Application.Unlock
  57.     
  58.     if( 0 = Len( g_strLocalHostName ) ) or ( 0 = Len( g_strLocalHostIP ) )then
  59.         SyncWithApplicationState
  60.     end if
  61.  
  62.     g_bServerlistFileExists = g_FileSysObj.FileExists( g_strXMLPath )
  63.     g_dwNumAvailableServers = -1
  64.     g_bRequireSSL = -1
  65.     g_bNeverShowSSLWarning = -1
  66.     
  67.     ' init MSXML
  68.     if( IsEmpty( g_xmlDoc ) ) then
  69.         Set g_xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
  70.     end if
  71.     g_xmlDoc.async = FALSE
  72.     g_xmlDoc.validateOnParse = TRUE
  73.     g_xmlDoc.preserveWhiteSpace = FALSE
  74.     
  75.     g_bInitialized = TRUE
  76. End Sub
  77.  
  78.  
  79. '////////////////////////////////////////////////////////////////
  80. Function ServerListFileExists()
  81.     if( FALSE = g_bInitialized ) then
  82.         InitializeFileIO
  83.     end if
  84.     
  85.     ServerListFileExists = g_bServerlistFileExists
  86. End Function
  87.  
  88. '////////////////////////////////////////////////////////////////
  89. '
  90. '  Load the XML DOM, creating the XML server list if it doesn't already exist
  91. '
  92. Sub LoadServerList()
  93.  
  94.     if( FALSE = g_bInitialized ) then
  95.         InitializeFileIO
  96.     end if
  97.     
  98.     if( FALSE = g_bServerlistFileExists ) then
  99.         if( TRUE = CreateNewServerListFile() ) then
  100.             LoadXMLDoc
  101.         else
  102.             g_dwNumAvailableServers = 0
  103.         end if
  104.     else
  105.         ' Load the document into the XML DOM
  106.         LoadXMLDoc
  107.         CompressServers
  108.     end if
  109.     g_dwNumAvailableServers = GetNumberOfServers()
  110. End Sub
  111.  
  112.  
  113. '////////////////////////////////////////////////////////////////
  114. Sub LoadXMLDoc()
  115.     on error goto 0
  116.  
  117.     if( IsEmpty( g_FileSysObj ) ) then
  118.         Set g_FileSysObj = Server.CreateObject( "Scripting.FileSystemObject" )
  119.     end if
  120.         
  121.     if( FALSE = g_FileSysObj.FileExists( g_strXMLPath ) ) then
  122.         g_bServerlistFileExists = FALSE
  123.         g_strErrorDescription = "accessDenied"
  124.         g_bWellFormedXML = FALSE
  125.     else
  126.         g_bWellFormedXML = g_xmlDoc.load( g_strXMLPath )    
  127.         if( FALSE = g_bWellFormedXML ) then
  128.             g_strErrorDescription = "badXML"
  129.         end if
  130.     end if
  131.     
  132.     Set g_xmlRootNode = g_xmlDoc.childNodes( 1 )
  133. End Sub
  134.  
  135.  
  136. '////////////////////////////////////////////////////////////////
  137. Function GetNumberOfServers()
  138.     if( FALSE = g_bWellFormedXML ) then
  139.         GetNumberOfServers = 0
  140.         Exit Function
  141.     end if
  142.  
  143.     if( IsEmpty( g_xmlDoc ) or IsEmpty( g_xmlDoc.childNodes ) ) then
  144.         GetNumberOfServers = 0
  145.     else
  146.         Set xmlNodeCollection = g_xmlRootNode.selectNodes( "Server" )
  147.         GetNumberOfServers = xmlNodeCollection.length
  148.     end if
  149. End Function
  150.  
  151.  
  152. '////////////////////////////////////////////////////////////////
  153. Function GetServerNameByIndex( dwIndex, byRef strServerName )
  154.     Dim xmlNodeCollection
  155.     Dim xmlNode
  156.     strServerName = ""
  157.  
  158.     if( FALSE = g_bWellFormedXML ) then
  159.         GetServerNameByIndex = FALSE
  160.         Exit Function
  161.     end if
  162.     
  163.     GetServerNameByIndex = TRUE
  164.     xmlNodeCollection = empty
  165.     xmlNode = empty
  166.     
  167.     Set xmlNodeCollection = g_xmlRootNode.selectNodes( "Server" )
  168.     if( dwIndex >= xmlNodeCollection.length ) then
  169.         Exit Function
  170.     end if
  171.  
  172.     Set xmlNode = xmlNodeCollection( dwIndex )
  173.     strServerName = RemoveDangerousCharacters( Left( xmlNode.getAttribute( "Name" ), MAX_LEN_SERVERNAME ) )
  174.     if( Null = strServerName ) then 
  175.         strServerName = "??"
  176.     end if
  177.             
  178.     if( 0 < Len( strServerName ) ) then
  179.         GetServerNameByIndex = FALSE
  180.     end if
  181. End Function
  182.  
  183.  
  184. '////////////////////////////////////////////////////////////////
  185. Function GetServerNameAndIPByIndex( dwIndex, byRef strServerName, byRef strServerIP )
  186.     Dim xmlNodeCollection
  187.     Dim xmlNode
  188.     strServerName = ""
  189.     strServerIP = ""
  190.  
  191.     '
  192.     ' If there's an error (such as file permissions error), then we want to know about it
  193.     '
  194.     on error goto 0
  195.  
  196.     if( FALSE = g_bWellFormedXML ) then
  197.         GetServerNameAndIPByIndex = FALSE
  198.         Exit Function
  199.     end if
  200.     
  201.     GetServerNameAndIPByIndex = TRUE
  202.     xmlNodeCollection = empty
  203.     xmlNode = empty
  204.     
  205.     Set xmlNodeCollection = g_xmlRootNode.selectNodes( "Server" )
  206.     if( dwIndex >= xmlNodeCollection.length ) then
  207.         Exit Function
  208.     end if
  209.  
  210.     Set xmlNode = xmlNodeCollection( dwIndex )
  211.     strServerName = xmlNode.getAttribute( "Name" )
  212.     strServerIP = xmlNode.getAttribute( "ip" )
  213.     if( Null = strServerName ) then 
  214.         strServerName = "??"
  215.     else
  216.         if( 0 < Len( strServerIP ) ) then
  217.             on error resume next
  218.             err.Clear
  219.             strServerIP = s_WMSAdmin.ResolveToIP( strServerName )
  220.             if( 0 <> err.number ) then
  221. '                strServerName = ""
  222.                 strServerIP = ""
  223.                 GetServerNameAndIPByIndex = FALSE
  224.                 Exit Function
  225.             end if
  226.             xmlNode.SetAttribute "ip", strServerIP
  227.             g_xmlDoc.save( g_strXMLPath )
  228.             LoadXMLDoc
  229.         end if
  230.     end if
  231.             
  232.     if( ( 0 < Len( strServerName ) ) and ( 0 = Len( strServerIP ) ) ) then
  233.         GetServerNameAndIPByIndex = FALSE
  234.     end if
  235. End Function
  236.  
  237.  
  238. '////////////////////////////////////////////////////////////////
  239. '
  240. '  Creates an XML list file from scratch
  241. '
  242. Function CreateNewServerListFile()
  243.     CreateNewServerListFile = FALSE
  244.     on error resume next
  245.     Set pi = g_xmlDoc.createProcessingInstruction("xml", " version=""1.0"" encoding=""utf-16"" standalone=""yes""")
  246.  
  247.     Set g_xmlRootNode = g_xmlDoc.CreateNode( "element", "WMSAdmin", "" )
  248.     Set g_xmlDoc.documentElement = g_xmlRootNode
  249.     
  250.     g_xmlDoc.insertBefore pi, g_xmlDoc.childNodes.item(0)
  251.     
  252.     if( g_bLocalHostRunningWMS ) then
  253.         g_xmlDoc.save( g_strXMLPath )
  254.         g_bWellFormedXML = TRUE
  255.         
  256.         if( IsEmpty( g_FileSysObj ) ) then
  257.             Set g_FileSysObj = Server.CreateObject( "Scripting.FileSystemObject" )
  258.         end if
  259.             
  260.         g_bServerlistFileExists = g_FileSysObj.FileExists( g_strXMLPath )
  261.         
  262. '        AddServerToXMLDOM g_strLocalHostName, g_strLocalHostIP, strErr
  263.         AddServerToXMLDOM "localhost", "127.0.0.1", strErr
  264.         g_dwNumAvailableServers = 1
  265. '        PutNamedPreference "RequireSSL", "1"
  266.     else
  267.         g_xmlDoc.save( g_strXMLPath )
  268.     end if
  269.  
  270.     g_strErrorDescription = ""
  271.     g_bServerlistFileExists = TRUE
  272.     CreateNewServerListFile = TRUE
  273. End Function
  274.  
  275.  
  276. '////////////////////////////////////////////////////////////////
  277. Function IsServerNameInXMLDOM( strName )
  278. on error goto 0
  279.     IsServerNameInXMLDOM = TRUE
  280.  
  281.     if( FALSE = g_bWellFormedXML ) then
  282.         IsServerNameInXMLDOM = FALSE
  283.         Exit Function
  284.     end if
  285.     
  286.     strQueryString = "Server[@Name='" & strName & "']"
  287.     Set xmlMatchingNodes = g_xmlRootNode.selectNodes( strQueryString )
  288.     if( 0 = xmlMatchingNodes.length ) then
  289.         IsServerNameInXMLDOM = FALSE
  290.     end if
  291. End Function
  292.  
  293.  
  294. '////////////////////////////////////////////////////////////////
  295. Function IsServerIPInXMLDOM( strIPAddress )
  296.     Dim MatchingXMLNodes
  297.     IsServerIPInXMLDOM = FindServersByIP( MatchingXMLNodes, strIPAddress )
  298. End Function
  299.  
  300.  
  301. '////////////////////////////////////////////////////////////////
  302. Function FindServersByIP( byRef xmlMatchingServers, strIP )
  303.     FindServersByIP = Null
  304.  
  305.     if( FALSE = g_bWellFormedXML ) then
  306.         Exit Function
  307.     end if
  308.     
  309.     if( 0 >= Len( strIP ) ) then
  310.         Exit Function
  311.     end if
  312.     
  313.     strQueryString = "Server[@ip='" & strIP & "']"
  314.     Set xmlMatchingServers = g_xmlRootNode.selectNodes( strQueryString )
  315.     FindServersByIP = xmlMatchingServers.length
  316. End Function
  317.  
  318.  
  319. '////////////////////////////////////////////////////////////////
  320. Function AddServerToXMLDOM( strName, strIPAddress, byRef strErrString )
  321. on error goto 0
  322.     Dim bNameExists
  323.     bNameExists = FALSE
  324.     AddServerToXMLDOM = FALSE
  325.     strErrString = L_NOXMLADD_TEXT
  326.  
  327.     if( FALSE = g_bWellFormedXML ) then
  328.         strErrString = "badXML"
  329.         Exit Function
  330.     end if
  331.     
  332.     if( 0 >= Len( strName ) ) then
  333.         strErrString = "invalidarg"
  334.         Exit Function
  335.     end if
  336.  
  337.     if( 0 = strcomp( g_strLocalHostName, strName, vbStringCompare ) ) or ( strIPAddress = g_strLocalHostIP ) then
  338.         bNameExists = IsServerNameInXMLDOM( strName )
  339.         if( FALSE = bNameExists ) then
  340.             bNameExists = IsServerIPInXMLDOM( strIPAddress )
  341.         end if
  342.         if( bNameExists ) then
  343.             strErrString = "duplicate"
  344.             Exit Function
  345.         else
  346.             strName = "localhost"
  347.             strIPAddress = "127.0.0.1"
  348.         end if
  349.     end if
  350.  
  351.     if( ( FALSE = IsServerNameInXMLDOM( strName ) ) and _
  352.         ( FALSE = IsServerIPInXMLDOM( strIPAddress ) ) ) then
  353.         Set xmlServerNode = g_xmlDoc.CreateNode( "element", "Server", "" )
  354.     
  355.         xmlServerNode.setAttribute "Name", strName
  356.         xmlServerNode.setAttribute "ip", strIPAddress
  357.         g_xmlRootNode.appendChild( xmlServerNode )
  358.         
  359.         g_xmlDoc.save( g_strXMLPath )
  360.         AddServerToXMLDOM = TRUE
  361.         strErrString = ""
  362.     else
  363.         strErrString = "duplicate"
  364.     end if
  365. End Function
  366.  
  367.  
  368. '////////////////////////////////////////////////////////////////
  369. Function GetServerNodeByName( strName )
  370.     GetServerNodeByName = Null
  371.  
  372.     if( FALSE = g_bWellFormedXML ) then
  373.         Exit Function
  374.     end if
  375.     
  376.     if( 0 >= Len( strName ) ) then
  377.         STOP
  378.         Exit Function
  379.     end if
  380.     
  381.     Dim xmlServerNode
  382.     Dim xmlServerNodeAttributes
  383.     Dim xmlServerName
  384.     
  385.     Set xmlServerNode = g_xmlRootNode.firstChild
  386.     if( Null <> xmlServerNode ) then
  387.  
  388.         Do
  389.             Set xmlServerNodeAttributes = xmlServerNode.attributes
  390.             if( 0 = StrComp( strName, xmlServerNodeAttributes.Name, vbTextCompare ) ) then
  391.                 GetServerNodeByName = xmlServerNode
  392.                 Exit Function
  393.             end if
  394.             xmlServerNode = xmlServerNode.nextSibling
  395.         Loop until( Null <> xmlServerNode )
  396.         
  397.     end if
  398. End Function
  399.  
  400.  
  401. '////////////////////////////////////////////////////////////////
  402. Function GetServerNodeByIP( strIP )
  403.     GetServerNodeByIP = Null
  404.     
  405.     if( FALSE = g_bWellFormedXML ) then
  406.         Exit Function
  407.     end if
  408.     
  409.     if( 0 >= Len( strIP ) ) then
  410.         STOP
  411.         Exit Function
  412.     end if
  413.     
  414.     Dim xmlServerNode
  415.     Dim xmlServerNodeAttributes
  416.     Dim xmlServerName
  417.     
  418.     Set xmlServerNode = g_xmlRootNode.firstChild
  419.     If( Null <> xmlServerNode ) then
  420.  
  421.         Do
  422.             Set xmlServerNodeAttributes = xmlServerNode.attributes
  423.             If( 0 = StrComp( strIP, xmlServerNodeAttributes.ip, vbTextCompare ) ) then
  424.                 GetServerNodeByIP = xmlServerNode
  425.                 Exit Function
  426.             End If
  427.             xmlServerNode = xmlServerNode.nextSibling
  428.         Loop until( Null <> xmlServerNode )
  429.         
  430.     End If
  431. End Function
  432.  
  433.  
  434. '////////////////////////////////////////////////////////////////
  435. Sub RemoveServerByIndex( dwIndex )
  436.     Dim xmlServerNodeToRemove
  437.     
  438.     if( FALSE = g_bWellFormedXML ) then
  439.         Exit Sub
  440.     end if
  441.     
  442.     Set xmlServerNodeList = g_xmlRootNode.selectNodes( "Server" )
  443.     Set xmlServerNodeToRemove = xmlServerNodeList( dwIndex )
  444.     g_xmlRootNode.removeChild( xmlServerNodeToRemove )
  445.     
  446.     g_xmlDoc.save( g_strXMLPath )
  447.     LoadXMLDoc
  448. End Sub
  449.  
  450.  
  451.  
  452. '////////////////////////////////////////////////////////////////
  453. Sub CompressServers()
  454.     Dim xmlEachNode
  455.     Dim xmlMatchingNodes
  456.     Dim xmlServerNodeList
  457.     Dim xmlDuplicateNode
  458.     Dim xmlServerName
  459.     Dim bDuplicatesFound
  460.     Dim i
  461.     
  462.     if( FALSE = g_bWellFormedXML ) then
  463.         exit sub
  464.     end if
  465.     
  466.     bDuplicatesFound = FALSE
  467.  
  468. '    Set xmlServerNodeList = g_xmlDoc.selectNodes( "//WMSAdmin[Server/@Name != '']" )
  469.     strTmp = "Server"
  470.     Set xmlServerNodeList = g_xmlRootNode.selectNodes( strTmp )
  471.     
  472.     if( 0 < xmlServerNodeList.length ) then
  473.         i = 0
  474.         Do
  475.             Set xmlEachNode = xmlServerNodeList( i )
  476.             strIP = xmlEachNode.getAttribute( "ip" )
  477.  
  478.             dwNumMatches = FindServersByIP( xmlMatchingNodes, strIP )
  479.             
  480.             if( 1 < dwNumMatches ) then
  481.                 bDuplicatesFound = TRUE
  482.                 for dwIndex = 1 to ( xmlMatchingNodes.length - 1 )
  483.                     Set xmlDuplicateNode = xmlMatchingNodes( dwIndex )
  484.                     g_xmlRootNode.removeChild( xmlDuplicateNode )
  485.                 next
  486.                 
  487.                 if( bDuplicatesFound ) then
  488.                     g_xmlDoc.save( g_strXMLPath )
  489.                     LoadXMLDoc
  490.                     bDuplicatesFound = FALSE
  491.                 end if
  492.             end if
  493.                     
  494.             i = i + 1
  495.         Loop until xmlServerNodeList.length = i
  496.     end if    
  497. End Sub
  498.  
  499. ' ///////////////////////////////////////////////////////
  500. '
  501. '  Misc utils
  502. '
  503. ' ///////////////////////////////////////////////////////
  504.  
  505. '////////////////////////////////////////////////////////////////
  506. Function BuildPathToXMLServerList()
  507.     Dim strPathToThisFile
  508.     Dim strPathToParentDir
  509.     Dim strUserPrefix
  510.  
  511.     on error resume next
  512.  
  513.     strPathToThisFile = server.MapPath( Request.ServerVariables( "PATH_INFO" ) )
  514.     dwOffsetToLastSlash = InStrRev( strPathToThisFile, "\", -1, vbTextCompare )
  515.     strPathToParentDir = Left( strPathToThisFile, dwOffsetToLastSlash )
  516.     dwOffsetToLastSlash = InStrRev( strPathToParentDir, "\", -1, vbTextCompare )
  517.     strUserPrefix = Server.CreateObject( "WScript.Network" ).UserName
  518.     if( 0 = Len( strUserPrefix ) ) then
  519.         strUserPrefix = Request.ServerVariables( "REMOTE_USER" )
  520.         if( 0 < Len( strUserPrefix ) ) then
  521.             dwOffsetToLastSlash = InStrRev( strUserPrefix, "\", -1, vbTextCompare )
  522.             if( 0 < dwOffsetToLastSlash ) then
  523.                 strUserPrefix = Right( strUserPrefix, Len( strUserPrefix ) - dwOffsetToLastSlash )
  524.             end if
  525.         end if
  526.     end if
  527.  
  528.     if( FALSE = g_FileSysObj.FileExists( strPathToParentDir & "Users" ) ) then
  529.         g_FileSysObj.CreateFolder( strPathToParentDir & "Users" )
  530.     end if
  531.  
  532.     BuildPathToXMLServerList = strPathToParentDir & "Users\" & strUserPrefix & "_" & SERVERLISTFILENAME
  533. '   BuildPathToXMLServerList = Left( strPathToThisFile, dwOffsetToLastSlash ) & SERVERLISTFILENAME
  534. End Function
  535.  
  536.  
  537.  
  538. '////////////////////////////////////////////////////////////////
  539. '
  540. ' Support for creating and managing user preferences
  541. '
  542. '////////////////////////////////////////////////////////////////
  543.  
  544.  
  545. '////////////////////////////////////////////////////////////////
  546. Function GetNamedPreference( strPrefAttrName )
  547.     Dim xmlNodeCollection
  548.     Dim xmlNode
  549.     Dim xmlPropsNode
  550.     
  551.     if( FALSE = g_bInitialized ) then
  552.         LoadServerList
  553.     end if
  554.     
  555.     if( 0 = strcomp( strPrefAttrName, "RequireSSL", vbStringCompare ) ) then
  556.         if( -1 <> g_bRequireSSL ) then
  557.             GetNamedPreference = g_bRequireSSL
  558.             Exit Function
  559.         end if
  560.     else
  561.         if( -1 <> g_bNeverShowSSLWarning ) then
  562.             GetNamedPreference = g_bNeverShowSSLWarning
  563.             Exit Function
  564.         end if
  565.     end if
  566.     
  567.     GetNamedPreference = FALSE
  568.     
  569.     if( FALSE = g_bWellFormedXML ) then
  570.         Exit Function
  571.     end if
  572.  
  573.     xmlNodeCollection = empty
  574.     xmlNode = empty
  575.     xmlPropsNode = empty
  576.     
  577.     Set xmlNodeCollection = g_xmlRootNode.selectNodes( "Preferences" )
  578.     if( 0 = xmlNodeCollection.length ) then
  579.         if( 0 = strcomp( strPrefAttrName, "RequireSSL", vbStringCompare ) ) then
  580.             PutNamedPreference strPrefAttrName, g_bRequireSSL
  581.             GetNamedPreference = g_bRequireSSL
  582.         else
  583.             PutNamedPreference strPrefAttrName, g_bNeverShowSSLWarning
  584.             GetNamedPreference = g_bNeverShowSSLWarning
  585.         end if
  586.         Exit Function
  587.     end if
  588.     
  589.     Set xmlPrefsNode = xmlNodeCollection( 0 )
  590.     if( IsEmpty( xmlPrefsNode ) ) then
  591.         if( 0 = strcomp( strPrefAttrName, "RequireSSL", vbStringCompare ) ) then
  592.             g_bRequireSSL = TRUE
  593.             PutNamedPreference strPrefAttrName, g_bRequireSSL
  594.             GetNamedPreference = g_bRequireSSL
  595.         else
  596.             g_bNeverShowSSLWarning = TRUE
  597.             PutNamedPreference strPrefAttrName, g_bNeverShowSSLWarning
  598.             GetNamedPreference = g_bNeverShowSSLWarning
  599.         end if
  600.         Exit Function
  601.     end if
  602.  
  603.     g_bRequireSSL = ( 0 = strcomp( "1", xmlPrefsNode.getAttribute( strPrefAttrName ), vbTextCompare ) )
  604.     GetNamedPreference = g_bRequireSSL
  605.  
  606. End Function
  607.  
  608.  
  609. '////////////////////////////////////////////////////////////////
  610. Function PutNamedPreference( strPrefAttrName, strAttrValue )
  611.     Dim xmlNodeCollection
  612.     Dim xmlNode
  613.     Dim xmlPropsNode
  614.  
  615.     if( FALSE = g_bInitialized ) then
  616.         LoadServerList
  617.     end if
  618.     
  619.     if( 0 = strcomp( strPrefAttrName, "RequireSSL", vbStringCompare ) ) then
  620.         g_bRequireSSL = ( 0 = strcomp( "1", strAttrValue, vbTextCompare ) )
  621.     else
  622.         g_bNeverShowSSLWarning = ( 0 = strcomp( "1", strAttrValue, vbTextCompare ) )
  623.     end if
  624.     
  625.     PutNamedPreference = TRUE
  626.     
  627.     if( FALSE = g_bWellFormedXML ) then
  628.         Exit Function
  629.     end if
  630.         
  631.     xmlNodeCollection = empty
  632.     xmlNode = empty
  633.     xmlPropsNode = empty
  634.             
  635.     Set xmlNodeCollection = g_xmlRootNode.selectNodes( "Preferences" )
  636.     if( 0 = xmlNodeCollection.length ) then
  637.         Set xmlPrefsNode = g_xmlDoc.CreateNode( "element", "Preferences", "" )
  638.         xmlPrefsNode.setAttribute "RequireSSL", strAttrValue
  639.         g_xmlRootNode.appendChild( xmlPrefsNode )        
  640.         g_xmlDoc.save( g_strXMLPath )
  641.         PutNamedPreference = TRUE
  642.     else
  643.         Set xmlPrefsNode = xmlNodeCollection( 0 )
  644.         if( IsEmpty( xmlPrefsNode ) ) then
  645.             Set xmlPrefsNode = g_xmlDoc.CreateNode( "element", "Preferences", "" )
  646.             g_xmlRootNode.appendChild( xmlPrefsNode )        
  647.         end if
  648.  
  649.         xmlPrefsNode.setAttribute strPrefAttrName, strAttrValue
  650.         
  651.         g_xmlDoc.save( g_strXMLPath )
  652.         PutNamedPreference = TRUE
  653.     end if    
  654. End Function
  655.  
  656. '////////////////////////////////////////////////////////////////
  657. '
  658. ' Free the various globals we created by server-side-including this file
  659. '
  660. Sub WMSFileIOASPCleanup
  661.     g_strErrorDescription = nothing
  662.     g_strLocalHostName = nothing
  663.     g_strLocalHostDNSName = nothing
  664.     g_strLocalHostIP = nothing
  665.     g_strDomainName = nothing
  666.     g_strXMLPath = nothing
  667.     g_bServerlistFileExists = nothing
  668.     g_bRequireSSL = nothing
  669.     g_bNeverShowSSLWarning = nothing
  670.     g_FileSysObj = nothing
  671.     g_bLocalHostRunningWMS = nothing
  672.     g_xmlDoc = nothing
  673.     g_xmlRootNode = nothing
  674.     g_dwNumAvailableServers = nothing
  675.     g_bWellFormedXML = nothing
  676.     g_bInitialized = nothing
  677. End Sub
  678.  
  679. %>